<?php
class MessageSource extends CDbMessageSource
{
	protected function loadMessagesFromDb($category,$language)
	{
           
            $command=Yii::app()->db->createCommand()
                ->select('id')
                ->from('Language')
                ->where('l=:language')
                ->bindParam(':language',$language)
                ->queryRow();

            $language = $command['id'];
            
            $command=Yii::app()->db->createCommand()
                ->select('id')
                ->from('LCategorySourceMessage')
                ->where('c=:category')
                ->bindParam(':category',$category)
                ->queryRow();
            $category = $command['id'];          
            
            $sql=<<<EOD
SELECT t1.message AS message, t2.translation AS translation
FROM {$this->sourceMessageTable} t1, {$this->translatedMessageTable} t2
WHERE t1.id=t2.message_source_id AND t1.category=:category AND t2.language=:language
EOD;
            $command=$this->getDbConnection()->createCommand($sql);
            $command->bindValue(':category',$category);
            $command->bindValue(':language',$language);
            $messages=array();
            foreach($command->queryAll() as $row)
                    $messages[$row['message']]=$row['translation'];

            return $messages;
        }
}